/*
 The contents of this file are subject to the Mozilla Public License
 Version 1.1 (the "License"); you may not use this file except in
 compliance with the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/

 Software distributed under the License is distributed on an "AS IS"
 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 License for the specific language governing rights and limitations
 under the License.

 Alternatively, the contents of this file may be used under the terms
 of the GNU Lesser General Public license (the  "LGPL License"), in which case the
 provisions of LGPL License are applicable instead of those
 above.

 For feedback and questions about our Files and Projects please mail us,
 Janek Schäfer (foxblock) , foxblock_gmail_com
 Alexander Matthes (Ziz) , zizsdl_at_googlemail.com
*/

#ifndef _LEVEL_H
#define _LEVEL_H

#include <iostream>
#include <vector>
#include <string>
#include <list>

class InteractionGroup;
class Level;
class BaseUnit;
class Physic;

#include "StateManager.hpp"
#include "Sprite.hpp"
#include "BaseUnit.hpp"
#include "SceneGraph.hpp"
#include "SurfaceSceneGraphElem.hpp"
#include "Physic.hpp"

class InteractionGroup {
    public:
        InteractionGroup(char* name);
        ~InteractionGroup();
        void addPlatform(BaseUnit* platform,NUMBER_TYPE speedLeft,NUMBER_TYPE speedRight,bool clever,bool vertical);
        void addSwitch(BaseUnit* switch_,bool negative);
        void addButton(BaseUnit* button,bool negative);
        std::vector<BaseUnit*> platform;
        std::vector<NUMBER_TYPE> platformSpeedRight;
        std::vector<NUMBER_TYPE> platformSpeedLeft;
        std::vector<bool> platformClever;
        std::vector<bool> platformDirection;
        std::vector<int> platformAfterCollisionWait;
        std::vector<bool> platformVertical;
        std::vector<BaseUnit*> switch_;
        std::vector<bool> switchOn;
        std::vector<bool> switchNegative;
        std::vector<BaseUnit*> button;
        std::vector<bool> buttonNegative;
    private:
        char* name;
};

class Level {
    public:
        Level(const char* filename);
        ~Level();
        SceneGraph* projectAll(int passedTime);
        int getWidth();
        int getHeight();
        void update(int passedTime);
        BaseUnit* getActivePlayer();
        void nextPlayer();
        void previousPlayer();
        int* collisionLayer; //6 Bit Up, Down, Left, Right, Reserved, Reserved
        static bool actionButtonPressed;
        bool chooseMode;
        NUMBER_TYPE chooseX,chooseY,velChooseX,velChooseY;
        Sprite* cursor;
        int chooseModeMode; //0 delete, 1 choose, 2 clone
        BaseUnit* clonedUnit;
        BaseUnit* selectedUnit;
        Physic* physic;
        std::vector<BaseUnit*> player;
        std::vector<BaseUnit*> box;
        std::vector<BaseUnit*>::iterator playerIterator;
        std::vector<Sprite*> usedSprites;
        Sprite** foregroundLayer;
        Sprite** playerLayer;
        Sprite** backgroundLayer;
        int getColor(char c,char d);
        Uint16 backgroundColor;
        int width,height;
        std::vector<InteractionGroup*> groups;
        bool right;
        std::vector<BaseUnit*> door;
        static bool axis_up;
        static char* nextLevel;
        Sprite* energySprite;
        int energy;
        int getEnergy();
        void setEnergy(int value);
        std::vector<BaseUnit*> bug;
        std::vector<bool> bugDirection;
        NUMBER_TYPE camx,camy;
        char givenFilename[256];
        std::vector<BaseUnit*> nega;
        std::vector<BaseUnit*> colletible;
        std::vector<BaseUnit*> unselectable;
        bool positionOK;
        std::vector<BaseUnit*> trophies;
        static bool got_collectible[4][8];
    private:
};
#endif
